package String.综合练习;

import java.util.Scanner;

public class 转换罗马数字 {
    public static void main(String[] args) {
        // 键盘录入一个字符串
        Scanner sc=new Scanner(System.in);
        String str="";
        while (true) {
            System.out.println("请输入一个字符串：");
            str = sc.next();
            if(readProof(str)){
                break;
            }else{
                System.out.println("输入的字符串有误 请重新输入");
            }
        }
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char c=str.charAt(i);
            int num=c-48;
            sb.append(numberToluoma(num)+" ");

        }
        System.out.println(sb);
    }
    public static String numberToluoma(int number){
        String[] luoma={"","I","II","III","IV","V","VI","VII","VIII","IX"};
        return luoma[number];
    }
    public static boolean readProof(String str){
        if(str.length()>9){
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            char c=str.charAt(i);
            if(c<'0' || c>'9'){
                return false;
            }
        }
        return true;
    }
}
